# coding: utf-8

'''
是用caffe的./build/tools/compute_image_mean -backend=$DBTYPE $EXAMPLE/cifar10_train_$DBTYPE $EXAMPLE/mean.binaryproto
可以获取均值文件。
那么均值到底长什么样子呢。
本脚本用python获取了均值，并输出其shape为：
(3, 32, 32)
表示了每个像素点位置的均值
'''

import numpy as np
import sys
import caffe

if len(sys.argv) != 3:
    print "Usage: python convert_mean.py mean.binaryproto mean.npy"
    sys.exit()

blob = caffe.proto.caffe_pb2.BlobProto()
bin_mean = open(sys.argv[1], 'rb').read()
blob.ParseFromString(bin_mean)
arr = np.array(caffe.io.blobproto_to_array(blob))
npy_mean = arr[0]

# (3, 32, 32)
print npy_mean.shape
# np.save(sys.argv[2], npy_mean)
